
<#include "/common/head.html"/>
<div id="subLayout" class="easyui-layout" data-options="fit:true, border:false">
	<div data-options="region:'center', border:false">
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
		        		
			            	<span class="search_item">
				            	<span class="item_text">库位名称: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="loc_name" id="loc_name" value=""/>
				            	</span>    
				            </span>
		            	<span class="search_item">
			            	<span class="item_text">所属仓库: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="storage_no" id="storage_no" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDatastorage_no.keySet() as key>,{id:'${key}', text:'${dictDatastorage_no.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
		            	<span class="search_item">
			            	<span class="item_text">库位类型: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="Loc_type" id="Loc_type" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDataLoc_type.keySet() as key>,{id:'${key}', text:'${dictDataLoc_type.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
		            	<span class="search_item">
			            	<span class="item_text">是否在用: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="is_use" id="is_use" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDatais_use.keySet() as key>,{id:'${key}', text:'${dictDatais_use.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
        </div>
        <div style="text-align: left; margin:6px;">
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportCsv()">导出</a>
            <a href="javascript:void(0)" class="easyui-linkbutton importBtn" iconCls="glyphicon-import" plain="true" onclick="importCsv()">导入</a>
            <div id="searchBtnWrap" style="float:right; padding-right:5px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch(this)">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
        </div>
    </div>
    
    </div>
    <div data-options="region:'east',split:true, border:false, collapsed:true, width:window.subPageWidth||'40%', title:window.subPageTitle||'子页面'">
    	<iframe id="subIframe" class="easyui-panel" data-options="fit:true,border:false"></iframe>
    </div>
</div> 

<script type="text/javascript">
var datagrid = $("#dg");

var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,        
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	multiSort:true,
        queryParams: getInitParam(),
        
        columns: [[
		         {field:'id', checkbox:true}
	           	 ,{field:'loc_no', title: '库位编号', width:70, sortable: true}
	           	 ,{field:'loc_barcode', title: '条码', width:100}
	           	 ,{field:'loc_name', title: '库位名称', width:80}
	           	 ,{field:'storage_no', title: '所属仓库', width:110}
	           	 ,{field:'tp_tnum', title: '总盘位数', width:60}
	           	 ,{field:'tp_cnum', title: '使用盘位数', width:80, sortable: true}
	           	 ,{field:'c', title: '存储状态', width:100, align:'center',styler:cellStyler,
	           		formatter: function(value, row, index){
	           			if (0.8<=row.tp_cnum/row.tp_tnum&&row.tp_cnum/row.tp_tnum<1){	 
	           				var num=row.tp_tnum-row.tp_cnum;
	           				return '只有'+num+'个空位';
	           			}	
	           			else if (row.tp_cnum/row.tp_tnum<0.8&&0<=row.tp_cnum/row.tp_tnum){		 
	           				var num=row.tp_tnum-row.tp_cnum;
	           				return '仍有'+num+'个空位';
	           			}
	           			else if (row.tp_cnum/row.tp_tnum==1){	           			
	           				return '托盘已满';
	     		  		} 	           			
	           		}	           	 
	           	 }
	         	,{field:'operate', title: '操作',align:'center', width: 100, 
	             	formatter: function(value, row, index){
	             		var html = "";
	             		html += '<a class="easyui-linkbutton color2" name="opera" href="javascript:void(0)" onclick="btnClick5(' + index + ')"></a>';
	     			  	return html;
	     		  	} 
	             }
	           ]],
	       onLoadSuccess:function(data){    
   	            $("a[name='opera']").linkbutton({text:'托盘管理',plain:true,iconCls:'glyphicon-th-list'});    
   	    	}, 
	     rowStyler:function(index,row){
					
					//if (row.tp_cnum/row.tp_tnum<1){
					//	return 'background-color:yellow;color:black;font-weight:bold;';
					//}	
					//else if (row.tp_cnum/row.tp_tnum==1){
					//	return 'background-color:red;color:#fff;font-weight:bold;';
					//}	
				}
	};
$(function() {
	handleAuthDataRule();
	datagrid.datagrid(dgOptions);
});

function cellStyler(value,row,index){      			
		if (0.8<=row.tp_cnum/row.tp_tnum&&row.tp_cnum/row.tp_tnum<1){			
			return 'background-color:#ffee00;color:green;font-weight:bold;';
		}
		else if (row.tp_cnum/row.tp_tnum<0.8&&0<=row.tp_cnum/row.tp_tnum){			
			return 'background-color:green;color:white;font-weight:bold;';
		}	
		else if (row.tp_cnum/row.tp_tnum==1){			
			return 'background-color:red;color:white;font-weight:bold;';
			//return '<span style="background-color:red;color:#ccc;font-weight:bold;">托盘已满</span>';
		}	
} 	           	 

function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", {
		queryParams: param
	})
}

function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	return param;
}

function getInitParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();	
		}
	});
	return param;
}

var initPara = zcurdGetParam();
function add() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("增加成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("库位管理-增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '800x500'});
}

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		datagrid.datagrid("reload");
	}
	top.openWindow("库位管理-编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '800x500'});
}

function del() {
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据！");
		return;
	}
	confirmMsg("确认删除？", function() {
		$.post("delete", {id: ids}, function(data) {
			showMsg("删除成功！");
			datagrid.datagrid("reload");
		});
	});
}

function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.openWindow("库位管理-详情", getCurrUrl("detailPage") + "?id=" + id, {size: '800x500'});
}

function exportCsv() {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sortName = option.sortName;
	param.sortOrder = option.sortOrder;
	window.location.href = "exportCsv?" + $.param(param);
}
function importCsv() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("导入成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("库位管理-导入", getCurrUrl("importCsvPage") + "?" + $.param(initPara), {size: '800x500'});
}
//按钮事件
window.btnClick5 = function(index) {
 var row = datagrid.datagrid("getRows")[index];
  var url = basePath + "/wms/tray/listPage?locId=" + row.id+"&tp_tnum="+row.tp_tnum;
  _openSubPage(url);
};

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

//扩展js
var operateWidth = 80;
var subPageWidth = "55%";
var subPageTitle = "托盘列表";
dgOptions.singleSelect=true;;
</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>
